package Day017_缓冲流_转换流_序列化流_打印流.ZuoYe;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author zhangyan
 * @date 2020/5/9 18:30
 */
public class Test2 {
    public static void main(String[] args) throws Exception {

        //创建Scanner对象
        Scanner sc = new Scanner(System.in);
        System.out.println("输入3个验证码:");

        //创建字符缓冲输出流对象
        BufferedWriter bw = new BufferedWriter(new FileWriter("Demo02\\aaa\\data.txt"));

        for (int i = 0; i < 3; i++) {
            String s = sc.next();
            bw.write(s);
            bw.newLine();
        }
        //关流
        bw.close();

        System.out.println("输入需要被校验的验证码");
        String s1 = sc.next();

        //创建字符缓冲输入流对象
        BufferedReader br = new BufferedReader(new FileReader("Demo02\\aaa\\data.txt"));


        //定义变量存储读到的数据
        String line = null;
        ArrayList<String> list = new ArrayList<>();

        //循环读取每行数据
        while ((line = br.readLine()) != null){
            list.add(line);
        }
        //判断是否包含
        if (list.contains(s1)){
            System.out.println("验证成功");
        }else {
            System.out.println("验证失败");
        }
        //关流
        br.close();
    }
}
